# -*- coding: utf-8 -*-
from datetime import datetime
from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.views.generic import TemplateView
from blog.models import Blog
from comments.models import Comments
from django import forms
# Create your views here.


class Blog_List(TemplateView):
    def get(self, request):
        result = Blog.objects.all()
        return render(request, 'blog.html', locals())


class Blog_View(TemplateView):
    def get(self, request, blog_id):
        result = Blog.objects.all().filter(id=blog_id)
        return render(request, 'blog.html', locals())

    def post(self, request, blog_id):
        blog = Blog.objects.get(id=blog_id)
        cm = Comments()
        cm.comments_author = request.POST.get('name', 'smly')
        cm.comments_create_time = datetime.now()
        cm.comments_desc = request.POST.get('message', '')
        cm.blog_comments = blog
        cm.save()
        cur_url = request.path
        return HttpResponseRedirect(cur_url)